草庐IT

Angular 单元测试简介

全部标签

javascript - 使用依赖注入(inject)和 `done` 编写 Karma + Mocha 测试?

在既有依赖注入(inject)又完成的mocha中编写Karma单元测试的最优雅的方法是什么?依赖注入(inject):describe('cows',function(){it('fartsalot',inject(function(cow){//dostuff}))})完成:describe('cows',function(){it('fartsalot',function(done){//dostuff})})如果我想在我的单元测试中同时使用cow和done怎么办?现在,这就是我正在做的,但并不令人满意。beforeEach(inject(function(cow){this.c

javascript - 测试选项卡导航顺序

在我们的一项测试中,我们需要确保以正确的顺序执行表单内的选项卡键盘导航。问题:传统的用Protractor检查tab导航顺序的方法是什么?目前我们正在通过对表单中存在的尽可能多的输入字段重复以下步骤来解决此问题(代码如下):检查当前聚焦元素的ID(使用getId())将TAB键发送到当前获得焦点的元素这是规范示例:it("shouldnavigatewithtabcorrectly",function(){varregCodePage=newRegCodePage();browser.wait(protractor.ExpectedConditions.visibilityOf(reg

javascript - $window.print(),在angular js中不打印更新后的模型数据

我有一个包含一些数据的表格,可以在html中查看。当我点击打印时,我需要从数据库中获取所有数据并打印出来。当我点击打印时,我正在获取数据并填充模型数据,只有模型被更新,打印显示旧数据。在下面的代码中,当我单击打印时,新项目不会添加到项目中。http://jsfiddle.net/vijaivp/Y3BJa/306/HTMLOverallReportNamePriceQuantity{{item.Name}}{{item.Price}}{{item.Quantity}}JSfunctionPrintCtrl($scope,$window,$q){$scope.items=[{Name:"

javascript - Angular ng-model 动态 getter 和 setter

我想将ng-model与外部模型服务一起使用。该模型有两个方法:getValue(variable)和setValue(variable)。所以在我的html中我希望能够做到:Note:balanceisnotdefinedon$scopeinmycontroller.Andbecausewearedealingwithmorethen4000differentvariables,Idon'twanttodefinethemallon$scope.然后在更改时它必须调用模型的setValue()方法。所以在我的Controller中我想有这样的东西:$catchAllGetter=fu

javascript - 当我在 html 标签中使用 ng-controller 时,Angular 停止工作

这个问题在这里已经有了答案:Controllernotafunction,gotundefined,whiledefiningcontrollersglobally(14个答案)关闭7年前。我是Angular.js的新手,开始在plunker.co上学习Angular。问题是当我在html页面的任何标签中使用ng-controller时,angular停止工作。我的意思是{{4+4}}显示,因为它是在使用ng-controller之后显示的。这是来自Plunker.co的代码HelloPlunker!{{8*8}}{{message}}没有ng-controller它显示64作为输出但

javascript - 为什么我们使用缩小版的 Angularjs(即使我们添加了 angular.min.js.map,也要优先使用 angular.min.js 而不是 angular.js)

这个问题在这里已经有了答案:angular.min.js.mapnotfound,whatisitexactly?(2个答案)关闭7年前。我将angular.min.js添加到我的项目中并遇到了这个问题。http://localhost:8000/AngularProject/angular.min.js.map404(NotFound)angular.min.js.map:1经过研究,我发现添加angular.min.js.map可以消除“404(未找到)”错误。我还找到了“angular.min.js.map”的原因:我们添加它是因为“sourcemapfilesbasically

javascript - 在 Angular 中使用 $http.put 的例子?

有没有在Angular中使用$http.put方法的简单示例?具体来说,我不确定data/Requestcontent参数应该是什么,它应该是对象还是对象属性?$http.put(url,data,[config]); 最佳答案 第二个参数必须是一个对象:$http.put('/api/v1/users/'+user.login,{login:"login",password:"password"}); 关于javascript-在Angular中使用$http.put的例子?,我们在S

javascript - 使用 Jasmine 测试 Angular Controller 中的非作用域函数

Jasmine是使用最广泛的测试框架之一,以BDD方式对javascript代码进行单元测试。我试图将它用于AngularJS组件测试。AngularJS文档提供了以下示例代码describe('PasswordController',function(){beforeEach(module('app'));var$controller;beforeEach(inject(function(_$controller_){$controller=_$controller_;}));describe('$scope.grade',function(){it('setsthestrength

javascript - 无法监视 angular.element

我有一个Jasmine测试由于spyOn未执行而不断失败。下面的测试会自动失败:it('simpletest',function(){spyOn(angular,'element');});错误是:TypeError:'undefined'isnotanobject(evaluating'angular.element(handle.elem).off')at/Users/geoff/Project/www/components/angular-mocks/angular-mocks.js:1946at/Users/geoff/Project/www/components/angula

javascript - Protractor 测试元素是否为空

我想测试这个div元素为空。varmessagesDiv=element(by.id('messagesDiv'));expect(messagesDiv).to...我将如何实现? 最佳答案 我认为:expect(messagesDiv.getText()).toBe('');应该可以解决问题。更多信息here. 关于javascript-Protractor测试元素是否为空,我们在StackOverflow上找到一个类似的问题: https://stack